package patterns.protoType.core;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class ProtoType implements Cloneable, Serializable{
	private static final long serialVersionUID = -5540931732611922729L;
	private String string;
	
	private SerializableObject serializableObject;

	public Object clone() throws CloneNotSupportedException{
		ProtoType protoType = (ProtoType) super.clone();
		return protoType;
	}
	
	public Object deepClone() throws IOException, ClassNotFoundException{
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.writeObject(this);
		
		ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
		ObjectInputStream ois = new ObjectInputStream(bis);
		return ois.readObject();
	}

	public String getString() {
		return string;
	}

	public void setString(String string) {
		this.string = string;
	}

	public SerializableObject getSerializableObject() {
		return serializableObject;
	}

	public void setSerializableObject(SerializableObject serializableObject) {
		this.serializableObject = serializableObject;
	}
}
